def lil(a):
    d = True
    for s in range(2, int(a ** 0.5)+1):
        if a % s ==0:
            d = False
    return d
h = int(input())
if h < 1000 or h > 9999:
    print(0)
else:
    bdsm = str(h)
    mx = 0
    for k in range(len(bdsm)):
        for f in range(k+1, len(bdsm)+1):
            num = int(bdsm[k:f])
            if lil(num):
                mx = max(mx, num)
    print(mx)